import sys
from PyQt5.QtWidgets import (QWidget, QTableWidget,QComboBox,QPushButton,QHBoxLayout, QApplication, QTableWidgetItem,QHeaderView,QAbstractItemView)


class MyTableWidget(QWidget):
    def __init__(self):
        super(MyTableWidget, self).__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle("单词收藏本")
        self.resize(430, 300);
        layout = QHBoxLayout()
        tableWidget = QTableWidget()
        tableWidget.setRowCount(10)
        tableWidget.setColumnCount(3)

        layout.addWidget(tableWidget)

        tableWidget.setHorizontalHeaderLabels(['单词', '收藏时间', '取消收藏'])
        textItem = QTableWidgetItem('aback')
        tableWidget.setItem(0, 0, textItem)

        textItem = QTableWidgetItem('2021-4-24')
        tableWidget.setItem(0, 1, textItem)
        modifyButton = QPushButton('取消')
        modifyButton.setDown(True)
        modifyButton.setStyleSheet('QPushButton{margin:3px};')
        tableWidget.setCellWidget(0, 2, modifyButton)
        textItem = QTableWidgetItem('abate')
        tableWidget.setItem(1, 0, textItem)
        textItem = QTableWidgetItem('2021-4-25')
        tableWidget.setItem(1, 1, textItem)
        modifyButton = QPushButton('取消')
        modifyButton.setDown(True)
        modifyButton.setStyleSheet('QPushButton{margin:3px};')
        tableWidget.setCellWidget(1, 2, modifyButton)
        tableWidget.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch)

        self.setLayout(layout)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    example = MyTableWidget()
    example.show()

    sys.exit(app.exec_())
